<?php
	$path_one = 'admin/admin_project';
	$path_two = 'admin/admin_address_device_log';
	$filename = 'admin/admin_address_device_log';
	require_once("header.php");
	require_once("admin_comm.php");
	require_once $_site->get_handlepath('project');
	require_once $_site->get_handlepath('device');
	$page=request('page',false,true,false,1);
	$pagesize=request('pagesize',false,true,false,60);
	$pagesize = is_numeric($pagesize)?$pagesize:60;
	$data['pid']=request('pid',false,true,false,0);
	$data['state']=request('state',false,true,false,1);
	$data['address']=request('address',true,false,false,0);//作业点id
	$data['no']=request('no',true,false,false,0);
	$data['type']=$type=request('type',true,false,false,1);
	$data['truck']=$truck=request('truck',true,false,false,0);
	$data['dust']=$dust=request('dust',true,false,false,0);
	$data['onload']=$onload=request('onload',true,false,false,0);
	$data['dname']=$dname=request('dname');
	$data['jsno']=$jsno=request('jsno');
	$data['dkno']=$dkno=request('dkno');
	$data['fbtime']=$fbtime=request('fbtime');
	$no_title=request('no_title');
	$gcat=request('gcat',true,false,false,-1);
	if($gcat>-1)$data['gcat']=$gcat=(1==$gcat)?1:0;

	//合理时间
	$time_hl=request('time_hl',false,true,false,120);
	if($time_hl<=0 || $time_hl>86400)$time_hl=120;

	$start_time=$data['start_time']=request('start_time');
	$end_time=$data['end_time']=request('end_time');
	if(empty($start_time) && empty($end_time)){
		$now_time=strtotime(date("Y-m-d",time()));
		$start_time=$data['start_time']=date("Y-m-d H:i:s",$now_time);
		$end_time=$data['end_time']=date("Y-m-d H:i:s",$now_time+86399);
	}

	$result = device_fun_get_checkin_list($data,$page,$pagesize);

	$hover[$data['state']]=' class="hover" ';
	$address_list = $data['pid']&&$data['address']==false?$project->get_project_address_list(array('all'=>true,'pid'=>$data['pid'])):false;//作业点列表
	if($data['address']){
		$address_info = project_fun_get_project_address_info($data['address']);
	}
	$truckType=array('a'=>'A 型','b'=>'B 型','c'=>'C 型');
	$dustType=array('1'=>'Ⅰ类','2'=>'Ⅱ类','3'=>'Ⅲ 类');
	$onloadType=array(1=>"空车",2=>"重车");
	$stateType=array(1=>"有效",0=>"无效");

	function time2second($seconds){
		$seconds = (int)$seconds;
		if( $seconds<86400 ){//如果不到一天
			$format_time = gmstrftime('%H 时 %M 分 %S 秒 ', $seconds);
		}else{
			$time = explode(' ', gmstrftime('%j %H %M %S', $seconds));
			$format_time = ($time[0]-1).'天'.$time[1].'时'.$time[2].'分'.$time[3].'秒';
		}
		return $format_time;
	}
?>
<link rel="stylesheet" type="text/css" href="/static/skin/green/css/list.css">
<script type="text/javascript" charset="utf-8">

	loader.file({
		plugin:['validform/main','dialog/main','my97/wdatepicker']
	})
	function get_project_info (){
		dialog.iframe({
			title:'项目选择',
			is_resize:false,
			top:{
				is_show:true,
				btn_max:false,
				btn_min:false,
				btn_close:true,
				height:33,
				is_move:true
			},
			is_scroll:false,
			min_width:380,
			min_height:400,
			is_center:true,
			is_lock_back:true,
			content:'/admin/common_choise?callback=set_project_info&parm=state.1',
			name:'choise_project'
		});
	}

	function set_project_info(id,title){
		if(id && title){
			$("#pid").val(id);
			$("#name_title").val(title);
			get_address_list(id);
		}
	}

	function get_address_list(pid,coord){
		if(!pid) return false;
		$.ajax({
			type:'get',//Get or Post
			url:'/handle.php',
			cache:false,//false
			dataType:'json',
			data:'h=project/address_list&pid='+pid,
			beforeSend:function(XMLHttpRequest){

			},
			success:function(data){
				if(data.list){
					var strHtml = '<option value="">≡选择最近的作业点≡</option>';
					for (var i in data.list){
						var h = data.list[i]['id']=='<?php echo $data['address'];?>'?'selected':'';
						strHtml+='<option '+h+' value="'+data.list[i]['id']+'">'+data.list[i]['title']+'</option>';
					}

				}else{
					var strHtml = '<option value="">≡选择最近的作业点≡</option>';
				}
				$('#address').html(strHtml);
			}
		});//Ajax End
	}
	window.onload=function (){
		get_address_list('<?php echo $data['pid'];?>','<?php echo $data['address'];?>');
	}

	function import_out(obj){
		//if($("#onload").val()==''){alert('请选择装载情况：空车或重车');return false;}
		var _this=$(obj);
		var request_url = _this.parents('form').serialize();
		window.location.href="/handle.php?h=device/improt_out&"+request_url;
		return false;
	}

	function import_out_all(obj){
		var _this=$(obj);
		var request_url = _this.parents('form').serialize();
		window.location.href="/handle.php?h=device/improt_out_all&"+request_url;
		return false;
	}

    //数据校验
	function data_verify(obj){
		var _this=$(obj);
		var request_url = _this.parents('form').serialize();
		window.location.href="/?v=/admin/device_data_check&"+request_url;
		return false;
	}

	function import_out_als(obj){
		var _this=$(obj);
		var request_url = _this.parents('form').serialize();
		window.location.href="/handle.php?h=device/improt_out_all&all=1&"+request_url;
		return false;
	}

	function zippack(obj){
		var _this=$(obj);
		var item_id = '<?php echo $data['pid'];?>';
		var item_name = '<?php echo $no_title;?>';
		var start_time='<?php echo $data['start_time'];?>'
		var end_time='<?php echo $data['end_time'];?>'
		if(!item_id || !item_name){
			alert('请先选择项目');
			return ;
		}
		window.location.href='/handle.php?h=device/zip_pack&item_id='+item_id+'&item_name='+item_name+'&start_time='+start_time+'&end_time='+end_time;
	}

	function nouse(id){
       if(!confirm('确认设置记录为无效 ？')){
            return false;
       }

       $.getJSON('/handle.php',{id:id,h:'project/nouse'},function(res){
           if(res.state){
                 $("#no_"+id).remove();
                 return false;
           }
           alert(res.msg);
       });
	}


    //修改记录
	function editinfo(id){
		dialog.iframe({
			title:'修改登记记录',
			is_resize:false,
			top:{
				is_show:true,
				btn_max:false,
				btn_min:false,
				btn_close:true,
				height:33,
				is_move:true
			},
			is_scroll:false,
			min_width:820,
			min_height:450,
			is_center:true,
			is_lock_back:true,
			content:'/admin/editinfo?id='+id,
			name:'choise_project'
		});
	}

    function choosetime(){
        dialog.iframe({
            title:'选择分班时间',
            is_resize:false,
            top:{
                is_show:true,
                btn_max:false,
                btn_min:false,
                btn_close:true,
                height:33,
                is_move:true
            },
            is_scroll:true,
            min_width:450,
            min_height:350,
            is_center:true,
            is_lock_back:true,
            content:'/admin/fbtime',
            name:'choise_fbtim'
        });
    }

    function clearfbtime(){
        $("#fbtime").val('');
        dialog.close('choise_fbtim');
    }

    function choosefbtime(datestr){
        $("#fbtime").val(datestr);
        dialog.close('choise_fbtim');
    }

	function change(info){
		var onload = '重车'==info.onload?'<span class="red">重车</span>':'<span class="green">空车</span>';
		var infos= $("#no_"+info.id).find("p:eq(0)").html().replace(/<span class="(red|green)">(空车|重车)<\/span>/,onload);
		$("#no_"+info.id).find("p:eq(0)").html(infos);
        $("#no_"+info.id).find("p:eq(3)").html("<strong>车型</strong>  "+info.truck+"   <strong>土石</strong>  "+info.dust);
	}
</script>
<style>
.goodimg{width:180px;height:263px;background: #efefef none repeat scroll 0 0;border: 1px solid #aad381;}
.goodwarn{width:180px;height:263px;background: #ff0 none repeat scroll 0 0;border: 1px solid #ff0000;}
.goodother{width:180px;height:263px;background: #07c4e2 none repeat scroll 0 0;border: 1px solid #ff0000;}
.table li{float:left;margin-right: 10px;margin-top: 10px;text-align: center;}
.table img{max-width:160px;height:120px;margin:5px;}
.table .text{text-align:left;margin-left:10px;}
.table .operation{background:#aad381}
</style>
</head>
<body>
	<div class="position_nav">你所在的当前位置：<?php echo $path_str;?></div>
		<div class="main">

			<div class="sos_box">
				<form action="/admin/admin_address_device_log" id="search" method='get'>
					<input type="hidden" name="type" value="1">
					<span>选择项目：</span>
					<input type="hidden" name="pid" id='pid' value="<?php echo $data['pid'] ;?>">
					<input type="text" name='no_title' id='name_title' readonly="readonly" value="<?php echo $no_title ;?>" onclick='get_project_info();'>
					<span>车牌号：</span>
					<input type="text"  name="dname" value="<?php echo $data['dname'] ;?>">
					<span>手机设备号：</span>
					<input type="text"  name="no" value="<?php echo $data['no'] ;?>">
					<span>机手编号：</span>
					<input type="text" style="width:150px" name="jsno" value="<?php echo $data['jsno'] ;?>">
					<span>地块编号：</span>
					<input type="text" style="width:150px" name="dkno" value="<?php echo $data['dkno'] ;?>">
					<span>最小合理时间(秒)：</span>
					<input type="text" style="width:80px" name="time_hl" value="<?php echo $time_hl; ?>">
					<div style="clear: both;width:100%;*height:0px;margin:5px 0;"></div>
					<span>渣车类型：</span>
					<select name='truck'>
					 <option value="">全部</option>
					   <?php
					      foreach($truckType as $key=>$val){
                          ?>
                          <option value="<?php echo $key?>" <?php if($key==$truck){echo "selected";} ?>><?php echo $val?></option>
                          <?php
                           }
					   ?>
					</select>
					<span>土石类型：</span>
					<select name='dust'>
					 <option value="">全部</option>
					   <?php
					      foreach($dustType as $key=>$val){
                          ?>
                          <option value="<?php echo $key?>" <?php if($key==$dust){echo "selected";} ?>><?php echo $val?></option>
                          <?php
                           }
					   ?>
					</select>
					<span>装载情况：</span>
					<select name='onload' id="onload">
					 <option value="">全部</option>
					   <?php
					      foreach($onloadType as $key=>$val){
                          ?>
                          <option value="<?php echo $key?>" <?php if($key==$onload){echo "selected";} ?>><?php echo $val?></option>
                          <?php
                           }
					   ?>
					</select>
                    <select name='gcat'>
                        <option value="">不饱和模式</option>
                        <option value="1" <?php if(1==$gcat){echo "selected";} ?>>是</option>
                        <option value="2" <?php if(0==$gcat){echo "selected";} ?>>否</option>
                    </select>
					<span>按登记时间段搜索：</span>
					<style type="text/css">
						#d4311,#d4312,#time_limit{background: url('http://www.my97.net/dp/My97DatePicker/skin/datePicker.gif') no-repeat right center;}
					</style>
					<input class='date_icon' type="text" id="d4311" name="start_time" value="<?php echo $start_time ;?>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'d4312\')||\'<?php echo date('Y-m-d');?>\'}',readOnly:true})"> -
					<input type="text" id="d4312" name="end_time" value="<?php echo $end_time ;?>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'d4311\')}',maxDate:'<?php echo date('Y-m-d');?>',readOnly:true})">
                    <input type="text"  name="fbtime" id="fbtime" value="<?php echo $fbtime ;?>" placeholder="设置分班时间" style="width:130px;" onclick="choosetime();" readonly>
					单页记录：<input type="text" style="width: 40px" name="pagesize" value="<?php echo $pagesize?>">
					<input class="button1" type="submit" value="搜索">
					<div style="clear: both;width:100%;*height:0px;margin:5px 0;"></div>
					<?php if($cookie['group']!=12){?>
					<input class="button1" type="button" onclick="import_out(this);return false;" value="导出统计报表">
					<input class="button1" type="button" onclick="import_out_all(this);return false;" value="导出记录">
					<input class="button1" type="button" onclick="import_out_als(this);return false;" value="导出全部记录">
					<input class="button1" type="button" onclick="data_verify(this);return false;" value="数据校验">
					<?php }?>
					<!-- <input class="button1" type="button" onclick="zippack(this);return false;" value="项目图片下载"> -->
					<div style="clear: both;width:100%;*height:25px;margin:5px 0;">
						<b class="red">提示:</b> 导出统计报表时，必须选择装载情况（空车或重车）</div>
					<div style="clear: both;width:100%;*height:0px;margin:5px 0;"></div>
				</form>
			</div>
			<table cellpadding="0" cellspacing="1" border="0" class="table">
				<?php
					if($result['rows']){
                 ?>
                 <tr><td>
                 <?php
				   foreach ($result['rows'] as $k=>$v){
                       $length=0;
                       if($result['rows'][$k+1]['ctime'])
                       $length=$v['ctime']-$result['rows'][$k+1]['ctime'];
                       //$_class=($length>900||$length<90)?'goodwarn':'goodimg';
                       $_class=($length<$time_hl && $length>0)?'goodwarn':'goodimg';
                       $_class=(1==$v['gcat'])?'goodother':$_class;
				 ?>
			     <li id="no_<?php echo $v['id'];?>">
                     <div class="<?php echo $_class;?>">
					 <a href="<?php echo $v['img'];?>" title="点击查看大图" target="_blank">
                     <img src='<?php $img=1==$v['delimg']?'/static/images/imgdel.jpg':$v['img'];echo $img ;?>' width="156px" height="80px">
					 </a>
                     <p class="text">
                        <?php if(0==$v['gcat']){ ?>
                        <?php echo "<span class='".((1==$v['onload'])?'green':'red')."'>登记</span>&nbsp;&nbsp;".date("y-m-d H:i",$v['ctime']) ;?>
                        <?php }else{ ?>
                        <?php echo "不饱和登记&nbsp;&nbsp;".date("y-m-d H:i",$v['ctime']) ;?>
                        <?php } ?>
                     </p>

                     <p class="text"><strong><?php echo $v['dno'] ;?></strong></p>
                     <p class="text"><strong>车牌号</strong>  <?php echo $v['dname'] ;?></p>
                         <?php if(0==$v['gcat']){ ?>
                     <p class="text">
                       <strong>车型</strong>  <?php echo $truckType[$v['truck']] ;?>
                       <strong>土石</strong>  <?php echo $dustType[$v['dust']] ;?>
                     </p>
                         <?php } ?>
                     <p class="text"><strong>机手编号</strong>  <?php echo $v['jsno'] ;?></p>
                     <p class="text"><strong>地块编号</strong>  <?php echo $v['dkno'] ;?></p>
                         <?php if(0==$v['gcat']){ ?>
                     <p class="text"><strong>登记间隔</strong> <span class="red"><?php echo time2second($length);?></span></p>
                         <?php }else{ ?>
                             <p class="text"><strong>&nbsp;</strong></p><p class="text"><strong>&nbsp;</strong></p>
                         <?php } ?>
                     <p class="operation">
                     <?php if($cookie['group']!=12){?>
                       <a href="javascript:;" onclick="editinfo(<?php echo $v['id'];?>);" >编辑</a>
                       &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" onclick="nouse(<?php echo $v['id'];?>);" title="点击设置记录无效">无效</a>
                       <?php } ?>
                     </p>
                     </div>
                 </li>
				<?php
						}
				?>
						</td></tr>
						<?php
					}else{
						?>
						<tr>
							<td colspan="10">暂无数据！</td>
						</tr>
						<?php
					}
				?>
				<tr>
					<td colspan="10">
						<div class="list_more">
							记录总数：<?php echo $result['row_count']?$result['row_count']:0 ;?>
							<?php
								echo page_method($result['row_count'], $page, $result['page_count'], 10, '?'.preg_replace('/(&page=\d*)/','',$_SERVER['QUERY_STRING']), false);
							?>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</div>
</body>
</html>


